/*
ID: guoxu1
PROG: pprime
LANG: C++
*/
#include <fstream>
#include <vector>
using namespace std;

#define cin fin
#define cout fout

inline int powmod( long long a, int b, unsigned int m )
{
	if( a == 0 ) return 0;
	if( a == 1 ) return 1;
	if( b == 0 ) return 1;

	long long r = 1;
	while( b != 0 )
	{
		int k = ( b & 0x01 ) ? a : 1;
		r *= k;
		if( r > m ) r %= m;
		b >>= 1;
		if( b != 0 )
		{
			a *= a;
			if( a > m ) a %= m;
		}
	}
	return r;
}

inline bool isprime( unsigned int n )
{
  if( powmod( 2, n - 1, n ) != 1 ) return false;
  if( powmod( 3, n - 1, n ) != 1 ) return false;
  if( powmod( 5, n - 1, n ) != 1 ) return false;
  if( powmod( 7, n - 1, n ) != 1 ) return false;
  return true;
}

int extendd( unsigned int n )
{
  unsigned int p = n;
  while( n > 0 )
  {
    p = p * 10 + n % 10;
    n = n / 10;
  }
  return p;
}

int extends( unsigned int n )
{
  unsigned int p = n;
  n = n / 10;
  while( n > 0 )
  {
    p = p * 10 + n % 10;
    n = n / 10;
  }
  return p;
}

int main()
{
  vector< unsigned int > pprimes;
  pprimes.push_back( 5 );
  pprimes.push_back( 7 );
  pprimes.push_back( 11 );  
  for( int e = 1; e <= 3; e ++ )
  {
    int end = 1;
    for( int k = 0; k < e; k++ ) end *= 10;
    for( int i = 1; i < 10; i += 2 )
    for( int j = 0; j < end; j++ )
    {
      unsigned int v = 0;
      unsigned int num = i * end + j;
      v = extends( num );
      if( isprime( v ) ) pprimes.push_back( v );
      v = extendd( num );
      if( isprime( v ) ) pprimes.push_back( v );
    }
  }

  ifstream fin( "pprime.in" );
  ofstream fout( "pprime.out" );

  unsigned int a = 0, b = 0;
  cin >> a >> b;
  for( vector< unsigned int >::iterator it = pprimes.begin(); it != pprimes.end(); it++ )
  {
    if( *it >= a && *it <= b )
    {
      cout << *it << endl;
    }
  }
  return 0;
}
